#include "Pbm.h"

#include <cstring>
using std::memset;

#include <sstream>
using std::ostringstream;

/*
	Pbm
*/

/*	public	*/

Pbm::Pbm(int width, int height) :
	_width(width),
	_height(height) {

	/* image */
	int imageSize = width * height;
	int* image = new int[imageSize];
	memset(image, 0, imageSize * sizeof(int));
	_image = image;
}

Pbm::~Pbm() {
	delete[] _image;
}

void Pbm::set(int x, int y, int value) {
	_image[y * _width + x] = value;
}

string Pbm::toString() const {
	ostringstream oss;
	oss << "P1\n";
	oss << "# blah\n";
	oss << _width << " " << _height << "\n";
	for(int j = 0; j != _height; ++j) {
		for(int i = 0; i != _width; ++i) {
			oss << _image[j * _width + i];
		}
		oss << "\n";
	}
	oss << "\n";

	return oss.str();
}

